<?php
require_once 'common.php';
require_once "Course.php";
require_once 'ResultData.php';
require_once 'config.php';


if (isGet()) {
    echo "不得以GET访问";
    exit;
}

$id = trim($_REQUEST['id']);


$result = new ResultData();
if ($id == "") {
    $result->code = 404;
    $result->msg = "id不能为空";
    exit(json_encode($result));
}

$course = new Course();
$result->data = $course;

$id = intval($id);

$con = mysqli_connect($servername, $username, $password, $database, $port);

if (!$con) {
    $result->code = 404;
    $result->msg = "数据库连接不上";
    exit(json_encode($result));
}

$sql = "SELECT id, course_name, course_no FROM t_course WHERE id = {$id}";

$record = $con->query($sql);

if ($record->num_rows > 0) {
    while ($row = $record->fetch_assoc()) {
        $course->id = $row["id"];
        $course->courseName = $row["course_name"];
        $course->courseNo = $row["course_no"];
    }
}

mysqli_close($con);


exit(json_encode($result));
